<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../js/global.js"></script>
		<script src="../js/checked.js"></script>
	</head>
	<body>
		
		<form id="formCreateUser" class="layui-form" action="" onsubmit="return false">
			<div class="layui-col layui-col-space8">
				<div class="layui-col-md2" style="width: 550px;" >
						<label class="layui-form-mid"><span style="color: red;">*</span>类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 型:  </label>
						<div class="layui-input-inline" style="width: 300px;">
							<select class="qu"  lay-filter="type" name="questionTypeId">
								<option></option>
							</select>
						</div>
				</div>
				<div class="layui-col-md2" style="width: 550px;" >
					<label class="layui-form-mid"><span style="color: red;">*</span>试&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 题:  </label>
					<div class="layui-input-inline" style="width: 300px;">
						
						<input type="text" name="questionContent"
							 class="layui-input" />
					</div>
				</div>
			</div>
			<br />
			<div class="layui-row layui-col-space8">
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 值:  </label>
					<div class="layui-input-inline" style="width: 300px;">
						
						<input type="number" name="questionScore"
							 class="layui-input" />
					</div>
				</div>
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>答&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 案:  </label>
					<div class="layui-input-inline" style="width: 300px;">
						<input type="text" name="questionAnswer"
							 class="layui-input" />
					</div>
				</div>
			</div>
			<br />
			<div class="layui-row layui-col-space8">
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>答案解析:</label>
					<div class="layui-input-inline"  style="width: 300px;">
				 <textarea  name="questionAnalysis" type="text"  class="layui-textarea" ></textarea>
					</div>
				</div>
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>难&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 度:  </label>
					<div class="layui-input-inline" style="width: 300px;">
						
						<input type="number" name="questionGrade"
							 class="layui-input" />
					</div>
				
				
			</div>
			<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>科&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 目:  </label>
					<div class="layui-input-inline" style="width: 300px;">
						<select class="su"   name="subjectId">
							<option></option>
						</select>
					</div>
				
				
			</div>
			<br />
			 <div id="choose"  style="display: none;">
			<!-- 选择题区域 -->
			<div class="layui-row layui-col-space8">
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid" ><span style="color: red;">*</span>选项A:  </label>
					<div class="layui-input-inline" style="width: 300px;">
						<input type="text" name="itemA"
							 class="layui-input" />
					</div>
					
				</div>
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>选项B:</label>
					<div class="layui-input-inline"  style="width: 300px;">
						<input type="text" name="itemB"
							 class="layui-input" />
					</div>
				</div>
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>选项C:</label>
					<div class="layui-input-inline"  style="width: 300px;">
						<input type="text" name="itemC"
							 class="layui-input" />
					</div>
				</div>
				<div class="layui-col-md2" style="width: 550px;">
					<label class="layui-form-mid"><span style="color: red;">*</span>选项D:</label>
					<div class="layui-input-inline"  style="width: 300px;">
						<input type="text" name="itemD"
							 class="layui-input" />
					</div>
				</div>
				</div>
			</div>
			<br />
			
		</div>
			<div class="layui-btn-container" style="text-align: center;">
				<button class="layui-btn" lay-submit="" lay-filter="addQuestion">添加</button>
			</div>
		</form>
		<script>
			layui.use(['form','layer'],function(){
				var $=layui.$,
				form=layui.form,
				layer=layui.layer;
				//渲染试题类型表
				$.get(globalData.examinationServer + '/questionType/listQuestionTypes', function(res) {
					var html = "";
					for (var i = 0; i < res.data.length; i++) {
						
						//html += "<input type="radio" name="${index}" value="res.data[i].questionTypeId+" title="${taoZimu}" $
						html += "<option  value=" + res.data[i].questionTypeId + ">" + res.data[i].questionTypeName + "</option>"
				
					}
					$(".qu").append(html);
				
					form.render('select')
				}, "json")
				//渲染试题类型表
				$.get(globalData.examinationServer + '/subject/listSubjects', function(res) {
					var html = "";
					for (var i = 0; i < res.data.length; i++) {
						
						//html += "<input type="radio" name="${index}" value="res.data[i].questionTypeId+" title="${taoZimu}" $
						html += "<option  value=" + res.data[i].subjectId + ">" + res.data[i].subjectName + "</option>"
				
					}
					$(".su").append(html);
				
					form.render('select')
				}, "json")
				
				form.on('select(type)', function(data,index){
				var	value=data.elem[data.elem.selectedIndex].text;
				if(value=='单选'||value=='多选'){
					$("#choose").css("display","");
				}else{
					$("#choose").css("display","none");
				}
				});
				//添加按钮提交监听
				form.on('submit(addQuestion)',function(obj){
					//var str=$("#formCreateUser").serialize();
					//console.log(obj.field);
					$.ajax({
						type : "post",
						url : globalData.examinationServer+'/question/insertQuestion',
						data:obj.field,//需要传递到服务端的数据
						dataType:'json',//服务端响应数据类型
						xhrFields: {
							withCredentials: true
						},
						// beforeSend: function(request) {
						// 	request.setRequestHeader("token", globalData.getCurToken());
						// },
						success : function(res) {
							if(res.code == 0){
									layer.msg('添加成功',{icon:1,time:2000},function(index){
										layer.close(index);
										//关闭父窗口并重载
										dkm._close();
										dkm._reload();
									});
									
								}else{
									layer.msg('添加失败',{icon:2,time:2000});
							}
						}
					});
					
					return false;
				});
				
				
			});
		</script>
	</body>
</html>
